package com.infore.airsupervise.other;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;

import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.bean.UserE;
import com.infore.airsupervise.ui.activity.LoginActivity;
import com.infore.airsupervise.ui.activity.StationVideoActivity;
import com.videogo.constant.Constant;
import com.videogo.openapi.EZOpenSDK;
import com.videogo.openapi.bean.EZAccessToken;

/**
 * EZOpenSDK广播接收类
 *
 * @features: 用于处理广播
 * @author: Ding Xinlin
 * @date: 2016/12/07 10:27
 */

public class EzvizBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        String message = intent.getStringExtra("message_extra");

        /**
         * 授权成功（此处可由服务器统一授权后再把accessToken返回到移动端）
          */
        if (TextUtils.equals(action, Constant.OAUTH_SUCCESS_ACTION)) {
            // 授权令牌会自动缓存，短期内无需再次认证
            EZAccessToken accessToken = EZOpenSDK.getInstance().getEZAccessToken();
            Log.e("accessToken", "------------->"+accessToken.getAccessToken());

            // 跳转到站点视频信息显示界面
            Intent toIntent = new Intent(context, StationVideoActivity.class);
            toIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(toIntent);
        }
        /**
         *  token过期 重新登录
         */
        if (TextUtils.equals(action, Constants.ACTION_INTENT_RELOGIN)){
        //    Log.d("LoginToken", "------------->"+UserE.getUserInfo().getToken());
            // 跳转到站点视频信息显示界面
            Intent toIntent = new Intent(context, LoginActivity.class);
            toIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(toIntent);
        }
        /**
         * 用户退出登录时
         */
//        if(TextUtils.equals(action,Constants.ACTION_INTENT_OUT)){
//            Intent it = new Intent(context,LocationSendService.class);
//            context.startService(it);
//        }

    }

}
